import { _decorator, Component, Node, EventMouse, EventKeyboard, systemEvent, SystemEvent, Event, macro } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('jianshu')
export class jianshu extends Component {
	// https://blog.csdn.net/qq_45021180/article/details/104338196
    start() {
		// this.node.on(Node.EventType.MOUSE_DOWN,(event)=>{
		// 	console.debug(event.getLocation())
		// 	if(event.getButton()==EventMouse.BUTTON_LEFT){
		// 		console.debug('左键')
		// 	}
		// 	if (event.getButton() == EventMouse.BUTTON_RIGHT) {
		// 		console.debug('右键')
		// 	}
		// })

		systemEvent.on(SystemEvent.EventType.KEY_DOWN,(event)=>{
			if(event.keyCode==macro.KEY.w){
				console.debug('www')
			}
		})
		// this.node.on(Node.EventType.TOUCH_START,(e)=>{
		// 	console.debug(e.getID())
		// 	console.debug(e.getLocation())
		// })

		this.node.on(Node.EventType.TOUCH_START, (e) => {
			// this.node.emit('my')
			this.node.dispatchEvent(new Event('my'))
		})
		this.node.on('my',()=>{
			console.debug('自定义事件')
		})
    }
    update(deltaTime: number) {
        
    }
	onDestroy(){
		this.node.off(Node.EventType.MOUSE_DOWN)
	}
}

